#! /usr/bin/python
# -*- coding:utf-8 -*-

## ========================================================================
## Copyright (C) 2007-2013  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ========================================================================

from page import *
from naviguation import *
from admin import *
import cgi

form = cgi.FieldStorage()  

print u"Content-type: text/plain"
print

if form.has_key(u"session"): 
   session = form[u"session"].value

if form.has_key(u"page_id"): 
   page_id = form[u"page_id"].value  
else:
   print u"<br/>*** Champ page_id vide ! ***"

# GET ADMIN CONTENT
adm=AdminCms()
print adm.getPageHeader()
print adm.getAdminMenu()

## GET CONTENT PAGE
if page_id:
   pg=Page()
   content=pg.getContent(page_id)
   page_title=pg.getTitle()
   nav_id=pg.getNavID()
   nav=Nav()
   menu=nav.getOneElement(nav_id)
   print "<tr><td colspan='3'><div id='active_page'><br/><h3>Edition de la page %s (ID: %s)</h3><br><br><ul><li>&nbsp;Titre (page) :&nbsp;<input type='text' size='10' id='page_title' value='%s'></li><li>&nbsp;Nom (menu) :&nbsp;<input type='text' size='10' id='nav_name' value='%s'></li><li>&nbsp;Titre (menu) :&nbsp;<input type='text' size='10' id='nav_title' value='%s'></li><li>&nbsp;Parent (menu) :&nbsp;<input type='text' size='3' id='nav_parent' value='%s'></li><li>&nbsp;Position (menu) :&nbsp;<input type='text' size='3' id='nav_position' value='%s'></li><li>&nbsp;OnClick (menu) :&nbsp;<input type='text' size='10' id='nav_onclick' value='%s'></li><li>&nbsp;Page par defaut :&nbsp;<input type='text' size='3' id='nav_selected' value='%s'></li></ul><br><br>Contenu de la page<br><textarea rows='10' cols='20' id='pg_content'>%s</textarea><br><input type='hidden' id='page_id' value='%s'><input type='hidden' id='nav_id' value='%s'><input type='button' onclick='updatePage()' value='Enregistrer' title='Sauvegarder les modifications'><br/><br/><a href='javascript:setup();'><img src='/img/edit_icon.png' height='16' width='16' title='Load TinyMCE'/></a></div></td></tr>" % ( page_title, nav_id, page_title, menu[u'name'], menu[u'title'], menu[u'parent_id'], menu[u'position'], menu[u'onclick'], menu[u'selected'], content, page_id, nav_id )

else:
   print u"<tr><td colspan='3'><div id='active_page'><br/>Page inexistante</div></td></tr>"

print adm.getPagesList()
print adm.getPageFooter()
